/**
 * Copyright 2007-2008 Vidar Svansson
 *     
 * This file is part of JAdapter.
 * 
 * JAdapter is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * JAdapter is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with JAdapter.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.jadapter.adapters;

import org.jadapter.Adapter;


/**
 * Convenient superclass for adapters.
 * Most stuff implemented here is to tell the runtime
 * what types the adapter applies to.
 * This is necessary because of generic type erasure.
 * 
 * @author Vidar Svansson
 *
 * @param <T> The type this adapter transforms to.
 * @param <F> The type this adapter transforms from.
 * 
 * @see org.jadapter.adapters.SimpleAdapter
 * 
 */
public abstract class AbstractAdapter<T,F> 
        implements Adapter<T, F> {

    private Class<F> from;
    private Class<T> to;
    
    public AbstractAdapter(Class<F> from, Class<T> to){
        this.from = from;
        this.to = to;
    }
    
    /**
     * Default constructor. Requires the type information to
     * be set using {@link #from(Class)} and {@link #to(Class)}.
     */
    public AbstractAdapter(){
        // no type information available here.
    }
    
    /**
     * 
     * @param from The type to adapt from.
     * @return reference to this object for chaining.
     */
    public AbstractAdapter<T, F> from(Class<F> from) {
        this.from = from;
        return this;
    }
    
    /**
     * 
     * @param to The type to adapt to.
     * @return reference to this object for chaining.
     */
    public AbstractAdapter<T, F> to(Class<T> to){
        this.to = to;
        return this;
    }
    
    /* (non-Javadoc)
     * @see org.jadapter.func.Transformers#from()
     */
    public Class<F> from(){ return from; }
    
    /* (non-Javadoc)
     * @see org.jadapter.func.Transformers#to()
     */
    public Class<T> to(){ return to; }
    
    
    /* (non-Javadoc)
     * @see org.jadapter.func.Transformers#transform(F)
     */
    public abstract T transform(F context);
    
}
